﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BlockMix.Utilities;

namespace BlockMix.Controls
{
    /// <summary>
    /// Interaction logic for BlockContainer.xaml
    /// </summary>
    public partial class BlockContainer : UserControl
    {
        public BlockContainer()
        {
            InitializeComponent();
        }

        #region Properties

        //public Boolean State
        //{
        //    get { return (Boolean)this.GetValue(StateProperty); }
        //    set { this.SetValue(StateProperty, value); }
        //}
        //public static readonly DependencyProperty StateProperty = DependencyProperty.Register(
        //  "State", typeof(Boolean), typeof(MyStateControl), new PropertyMetadata(false));


        public double Top
        {
            get
            {
                if (double.IsNaN(Canvas.GetTop(this)))
                {
                    return (double)0;
                }
                return Canvas.GetTop(this);
            }

            set
            {
                Canvas.SetTop(this, value);
            }
        }

        public double Left
        {
            get
            {
                if (double.IsNaN(Canvas.GetLeft(this)))
                {
                    return (double)0;
                }
                return Canvas.GetLeft(this);
            }

            set
            {
                Canvas.SetLeft(this, value);
            }
        }

        #endregion

        #region Event Handlers

        private void BlockContainer_Intialized(object sender, EventArgs e)
        {
            var blockSize = AppContext.BlockSize;
            var gameSize = AppContext.GameBlockSize;

            // adjust container
            AddBlock(0,0, Colors.Red);
            AddBlock(0,1, Colors.Yellow);
        }

        #endregion

        #region Methods

        internal void AddBlock(int positionX, int positionY, Color color)
        {
            var location = AppContext.ContainerPointToLocation(positionX, positionY);
            var block = new Block {Background = new SolidColorBrush(color), Left = location.X, Top = location.Y};
            container.Children.Add(block);
        }

        #endregion

    }
}
